namespace SS.WPF.Framework.Display.FileDialog
{
    using System;

    /// <summary>
    /// Represents a file type.
    /// </summary>
    public class FileType
    {
        private readonly string description;
        /// <summary>
        /// Gets the description of the file type.
        /// </summary>
        public string Description
        {
            get
            {
                return description;
            }
        }

        private readonly string fileExtension;
        /// <summary>
        /// Gets the file extension. This string start with a '.' point.
        /// </summary>
        public string FileExtension
        {
            get
            {
                return fileExtension;
            }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="FileType"/> class.
        /// </summary>
        /// <param name="description">The description of the file type.</param>
        /// <param name="fileExtension">The file extension. This string has to start with a '.' point.</param>
        /// <exception cref="ArgumentException">description is null or an empty string.</exception>
        /// <exception cref="ArgumentException">fileExtension is null, an empty string or doesn't start with a '.' point character.</exception>
        public FileType(string description, string fileExtension)
        {
            string errTxt = null;

            if (!string.IsNullOrEmpty(description))
            {
                if (!string.IsNullOrEmpty(fileExtension))
                {
                    if (fileExtension[0] == '.')
                    {
                        this.description = description;
                        this.fileExtension = fileExtension;
                    }
                    else
                    {
                        errTxt = "The argument fileExtension must start with the '.' character.";
                    }
                }
                else
                {
                    errTxt = "The argument fileExtension must not be null or empty.";
                }
            }
            else
            {
                errTxt = "The argument description must not be null or empty.";
            }

            if (!string.IsNullOrEmpty(errTxt))
            {
                throw new ArgumentException(errTxt);
            }
        }
    }
}